package com.atguigu.java;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 了解类加载器
 */
public class ClassLoaderTest {

    @Test
    public void test1(){
//        ClassLoader classLoader = ClassLoaderTest.class.getClassLoader();
//        System.out.println(classLoader);
//        System.out.println(classLoader.getParent());
//        System.out.println(classLoader.getParent().getParent());
        //系统类加载器 扩展类加载器  引导类加载器
        System.out.println(String.class.getClassLoader());
    }


    /*
    Properties:读取配置文件
     */
    @Test
    public void test2() throws IOException {
        Properties p = new Properties();
//        FileInputStream fis = new FileInputStream("/Users/yangchen/IdeaProjects/atguiguReflect/src/main/java/jdbc.properties");
//        p.load(fis);
        ClassLoader classLoader = ClassLoaderTest.class.getClassLoader();
        InputStream resourceAsStream = classLoader.getResourceAsStream("jdbc.properties");
        p.load(resourceAsStream);

        String user = p.getProperty("user");
        String password = p.getProperty("password");

        System.out.println(user);
        System.out.println(password);
    }
}
